﻿using DataAccess;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLogic
{
    public class WorkerBL: MarshalByRefObject
    {
        private WorkerDA workerDA;
        public override object InitializeLifetimeService()
        {
            return null;// live forever;
        }

        public WorkerBL()
        {
            workerDA = new WorkerDA();
        }

        public Worker createWorker()
        {
            return new Worker();
        }

        public bool checkLogin(string user, string pass)
        {
            Worker[] result = workerDA.getWorkersByRawQuery("select username, password from " +
                Common.NHAN_VIEN + " where username = '" + user + "' and password = '" + pass+"'");
            if(result ==null || result.Length<=0)
            {
                return false;
            }
            return true;
        }
        public int addWorker(Worker worker)
        {
            return workerDA.addWorker(worker);
        }

        public bool updateWorker(Worker worker)
        {
            return workerDA.updateWorker(worker);
        }

        public Worker getWorkerById(int workerId)
        {
            return workerDA.getWorkerById(workerId);
        }

        public Worker[] getAllWorker()
        {
            return workerDA.getAllWorker();

        }

        public bool updatePassword(int workerId, string newPass)
        {
            return workerDA.updatePassword(workerId, newPass);
        }

        public Worker[] getWorkersByRawQuery(string query)
        {
            return workerDA.getWorkersByRawQuery(query);
        }

    }
}
